#include <iostream>
using namespace std;
int r;
int a[1005][1005];
int b[1005][1005];
int main()
{
    cin>>r;
    for(int i=0;i<r;++i){
        for(int j=0;j<=i;++j){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<r;++i){
        b[i][0] = b[i-1][0]+a[i][0];
        b[i][i] = b[i-1][i-1]+a[i][i];
        for(int j=1;j<i;++j){
            b[i][j] = a[i][j]+max(b[i-1][j-1], b[i-1][j]);
        }
    }
    int max=0;
    for(int i=0;i<r;++i){
        if(b[r-1][i]>max){
            max = b[r-1][i];
        }
    }
    cout<<max<<endl;
    
    return 0;
}